import { reactive } from 'vue';

export const authState = reactive({
  isLoggedIn: !!localStorage.getItem('token'),
  username: localStorage.getItem('username') || '用户',
  userInitial: (localStorage.getItem('username') || '用户').charAt(0).toUpperCase(),
  role: localStorage.getItem('role') || '', 
});

export function updateUserState() {
  authState.isLoggedIn = !!localStorage.getItem('token');
  const storedUsername = localStorage.getItem('username');
  authState.username = storedUsername || '用户';
  authState.userInitial = (storedUsername || '用户').charAt(0).toUpperCase();
  authState.role = localStorage.getItem('role') || '';
}